<template>
  
  <div id="reward-home">

      <div style="background-color:#f0f0f0;">

      <a-menu mode="horizontal">
        <a-sub-menu>
            <span slot="title" class="submenu-title-wrapper" >
              <a-avatar :src="userinfo.avatar" style="margin-left:0.25rem; margin-right:0.55rem;" />
              {{ usertitle }} 
            </span>
            <a-menu-item-group title="应用中心">
            <a-menu-item key="setting:1" :to="`/stock/message`"  @click="redirectView('/stock/message')" >
                审批
            </a-menu-item>
            <a-menu-item key="setting:2" :to="`/stock/workspace`" @click="redirectView('/stock/workspace')" >
                工作台
            </a-menu-item>
            <a-menu-item key="setting:3" :to="`/stock/ranking`" @click="redirectView('/stock/ranking')" >
                排行榜
            </a-menu-item>
            <a-menu-item key="setting:4" :to="`/stock/setting`"  >
                系统设置
            </a-menu-item>
            </a-menu-item-group>
        </a-sub-menu>
      </a-menu>

      <a-row :gutter="24">
        <keep-alive>
          <a-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">

            <div id="" class="" style="padding-left:2.75rem;padding-top:0.25rem;padding-bottom:0.25rem;background-color:#fefefe;" >
              <a-breadcrumb>
                <template v-for="(elem,index) in breadcrumb">
                  <a-breadcrumb-item :key="elem.icon" :index="index" >
                    <a-icon :type="elem.icon" />
                    <span @click="redirectView(elem.path)">{{ elem.text }}</span>
                  </a-breadcrumb-item>
                </template>
              </a-breadcrumb>
            </div>

            <!-- 系统权限申请 -->
            <div style="background-color:#f0f0f0;">

              <div id="legal-apply-content" class="reward-apply-content" style="height:auto; background-color:#fefefe; margin-top:0px; margin-left: 2.5rem; margin-right: 2.5rem; margin-bottom: 5rem; border: 1px solid #f0f0f0; front-size: 1rem;" >

                <div class="reward-apply-header" style="height:80px; width:100%; text-align:center; margin-top:20px; font-size: 1.5rem; ">
                  系统权限申请
                </div>

                <div class="reward-apply-content-item reward-apply-content-title" style="padding-top:5px;">
                   <a-row style="border-top: 1px dash #f0f0f0;" >
                    <a-col class="reward-apply-content-title-text" :span="4" style="font-size:1.1rem;">
                      权限信息
                    </a-col>
                   </a-row>
                </div>

                <div v-if="isNull(id)" class="reward-apply-content-item" style="margin-top:5px;margin-bottom:5px; margin-right:10px;">
                  <a-row>
                    <a-col :span="4" style="font-size:1.0rem; margin-top:5px; text-align: center;">
                      <span style="position:relative;" ><span style="color:red;margin-right:0px;position:absolute;left:-10px;top:0px;">*</span>填报日期</span>
                    </a-col>
                    <a-col :span="8">
                      <a-input v-model="element.create_time" readonly placeholder="请填写填报日期！" @blur="validFieldToast('create_time')" style="border: 0px solid #fefefe;  border-bottom: 1px solid #f0f0f0;"  />
                    </a-col>
                    <a-col :span="4" style="font-size:1.0rem; margin-top:5px; text-align: center;">
                      <span style="position:relative;" ><span style="color:red;margin-right:0px;position:absolute;left:-10px;top:0px;">*</span>填报人员</span>
                    </a-col>
                    <a-col :span="8">
                      <a-input v-model="element.create_by" readonly placeholder="请输入填报人员！" @blur="validFieldToast('create_by')" style="border: 0px solid #fefefe;  border-bottom: 1px solid #f0f0f0;"  />
                    </a-col>
                  </a-row>
                </div>

                <div class="reward-apply-content-item" style="margin-top:5px;margin-bottom:5px; margin-right:10px;">
                  <a-row>
                    <a-col :span="4" style="font-size:1.0rem; margin-top:5px; text-align: center;">
                      <span style="position:relative;" ><span style="color:red;margin-right:0px;position:absolute;left:-10px;top:0px;">*</span>所属区域</span>
                    </a-col>
                    <a-col :span="8">
                      <a-cascader v-model="element.zonename" :options="options.zoneOptions" placeholder="请选择所属区域" @blur="validFieldToast('zonename')"  style="width:100%; border: 0px solid #fefefe;  border-bottom: 1px solid #f0f0f0;"  />
                    </a-col>
                    <a-col :span="4" style="font-size:1.0rem; margin-top:5px; text-align: center;">
                      <span style="position:relative;" ><span style="color:red;margin-right:0px;position:absolute;left:-10px;top:0px;">*</span>所属板块</span>
                    </a-col>
                    <a-col :span="8">
                      <a-select mode="single" v-model="element.platename"  @blur="validFieldToast('platename')"  placeholder="请选择所属行业！" style="width:100%; border: 0px solid #fefefe;  border-bottom: 1px solid #f0f0f0;">
                        <template v-for="(elem,index) in industryList ">
                          <a-select-option :key="elem" :index="index" :value="elem">
                            {{elem}}
                          </a-select-option>
                        </template>
                      </a-select>
                    </a-col>
                  </a-row>
                </div>

                <div class="reward-apply-content-item" style="margin-top:5px;margin-bottom:5px; margin-right:10px;">
                  <a-row>
                    <a-col :span="4" style="font-size:1.0rem; margin-top:5px; text-align: center;">
                      <span style="position:relative;" ><span style="color:red;margin-right:0px;position:absolute;left:-10px;top:0px;">*</span>项目公司/名称</span>
                    </a-col>
                    <a-col :span="8">
                      <a-auto-complete v-model="element.company" :data-source="companyDataSource" style="width: 100%; border: 0px solid #fefefe;  border-bottom: 1px solid #f0f0f0; " placeholder="请输入所属项目公司/名称！" />
                    </a-col>
                  </a-row>
                </div>

                <div class="reward-apply-content-item" style="margin-top:5px;margin-bottom:5px; margin-right:10px;">
                  <a-row>
                    <a-col :span="4" style="font-size:1.0rem; margin-top:5px; text-align: center;">
                      <span style="position:relative;" ><span style="color:red;margin-right:0px;position:absolute;left:-10px;top:0px;">*</span>账户名称</span>
                    </a-col>
                    <a-col :span="8">
                      <a-auto-complete v-model="element.userlist_reception_name" :data-source="userDataSource" style="width: 100%; border: 0px solid #fefefe;  border-bottom: 1px solid #f0f0f0; " placeholder="请输入账户名称！" @select="handleSelect" @search="handleSearch" />
                    </a-col>
                    <a-col :span="4" style="font-size:1.0rem; margin-top:5px; text-align: center;">
                      <span style="position:relative;" ><span style="color:red;margin-right:0px;position:absolute;left:-10px;top:0px;">*</span>OA账户</span>
                    </a-col>
                    <a-col :span="8">
                      <a-input v-model="element.userlist" :readonly="false" placeholder="请输入OA账户！" @blur="validFieldToast('userlist')" style="border: 0px solid #fefefe;  border-bottom: 1px solid #f0f0f0;"  />
                    </a-col>
                  </a-row>
                </div>

                <div class="reward-apply-content-item" style="margin-top:5px;margin-bottom:5px; margin-right:10px;">
                  <a-row>
                    <a-col :span="4" style="font-size:1.0rem; margin-top:5px; text-align: center;">
                      <span style="position:relative;" ><span style="color:red;margin-right:0px;position:absolute;left:-10px;top:0px;">*</span>岗位/角色</span>
                    </a-col>
                    <a-col :span="8">
                      <a-select mode="single" v-model="element.groupname"  @blur="validFieldToast('groupname')"  @change="handleChange" placeholder="请输入岗位/角色！" style="width:100%; border: 0px solid #fefefe;  border-bottom: 1px solid #f0f0f0;">
                        <template v-for="(elem,index) in roleList ">
                          <a-select-option :key="elem" :index="index" :value="elem.value">
                            {{ elem.name }}
                          </a-select-option>
                        </template>
                      </a-select>
                    </a-col>
                    <a-col :span="4" style="font-size:1.0rem; margin-top:5px; text-align: center;">
                      <span style="position:relative;" ><span style="color:red;margin-right:0px;position:absolute;left:-10px;top:0px;">*</span>拥有权限</span>
                    </a-col>
                    <a-col :span="8">
                      <a-select v-model="element.access" :readonly="false" mode="tags" placeholder="请输入拥有权限！" @blur="validFieldToast('access')" style="width: 100%" :token-separators="[',']" >
                        <a-select-option v-for="(item,index) in accessList" :index="index" :key="item.value">
                          {{ item.name }}
                        </a-select-option>
                      </a-select>
                    </a-col>
                  </a-row>
                </div>

                <div class="reward-apply-content-item" style="margin-top:5px;margin-bottom:5px; margin-right:10px;">
                  <a-row>
                    <a-col :span="4" style="height:auto; font-size:1.0rem; margin-top:5px; text-align: center;">
                      <span style="position:relative;" ><span style="color:red;margin-right:0px;position:absolute;left:-10px;top:0px;"></span>备注信息</span>
                    </a-col>
                    <a-col :span="20">
                      <a-textarea
                        v-model="element.remark"
                        placeholder="请输入备注信息！"
                        :auto-size="{ minRows: 4, maxRows: 100 }"
                        style="height:60px; border: 0px solid #fefefe;  border-bottom: 1px solid #f0f0f0;"
                      />
                    </a-col>
                  </a-row>
                </div>

                <div class="reward-apply-content-item" style="margin-top:5px;margin-bottom:5px; margin-right:10px;">
                  <a-row>
                    <a-col :span="20" style="height:auto; font-size:1.0rem; margin-top:5px; text-align: left;">
                      <span style="position:relative;color:red;float:left;margin-left:5.25rem;font-size:10px;" ><span style="color:red;margin-right:0px;float:left;position:absolute;left:-10px;top:0px;">*</span>注：股权管理员拥有所有权限；股权查询员拥有查询权限；系统管理员拥有系统管理权限；资质管理员拥有资质管理权限；产权管理员拥有知识产权管理权限。</span>
                    </a-col>
                  </a-row>
                </div>

                <div v-show="role != 'view' && isNull(id) " class="reward-apply-content-item" style="margin-top:35px;margin-bottom:5px; margin-right:10px;">
                   <a-row style="border-top: 1px dash #f0f0f0;" >
                    <a-col :span="8">
                    </a-col>
                    <a-col class="reward-apply-content-title-text" :span="4" style="">
                      <a-button type="primary" style="width: 120px;color:c0c0c0;" @click="handleSave();"  >
                        保存
                      </a-button>
                    </a-col>
                    <a-col class="reward-apply-content-title-text" :span="4" style="">
                      <a-button type="primary" style="width: 120px;" @click="handleApply();"  >
                        提交
                      </a-button>
                    </a-col>
                    <a-col :span="8">
                    </a-col>
                   </a-row>
                </div>

                <div v-show="role != 'view' && !isNull(id)  " class="reward-apply-content-item" style="margin-top:35px;margin-bottom:5px; margin-right:10px;">
                   <a-row style="border-top: 1px dash #f0f0f0;" >
                    <a-col :span="8">
                    </a-col>
                    <a-col class="reward-apply-content-title-text" :span="4" style="margin-left:100px;">
                      <a-button type="primary" style="width: 120px;color:c0c0c0;" @click="handlePatch();"  >
                        修改
                      </a-button>
                    </a-col>
                    <a-col :span="8">
                    </a-col>
                   </a-row>
                </div>

                <div style="height:100px;">
                </div>
              </div>
            </div>
          </a-col>
        </keep-alive>
      </a-row>
    </div>
  </div>
</template>
<script>
import * as workconfig from '@/request/workconfig';

export default {
  mixins: [window.mixin],
  data() {
    return {
      iswechat:false,
      iswework:false,
      pageName: "系统权限申请",
      momentNewMsg: true,
      activeTabKey: 3,
      acceptType:'*/*',
      uploadURL:'',
      tablename:'bs_admin_group',
      size: 0,
      options:{
        create_time:moment(dayjs().format('YYYY-MM-DD'),'YYYY-MM-DD'),
        in_time:moment(dayjs().format('YYYY-MM-DD'),'YYYY-MM-DD'),
        establish_time:moment(dayjs().format('YYYY-MM-DD'),'YYYY-MM-DD'),
        start_time:moment(dayjs().format('YYYY-MM-DD'),'YYYY-MM-DD'),
        coop_time:moment(dayjs().format('YYYY-MM-DD'),'YYYY-MM-DD'),
        out_time:moment(dayjs().format('YYYY-MM-DD'),'YYYY-MM-DD'),
        datetime:moment(dayjs().format('YYYY-MM-DD'),'YYYY-MM-DD'),
        zoneOptions:JSON.parse(`[{"label":"融量集团","value":"融量集团"},{"label":"地产板块","value":"地产板块","children":[{"label":"集团总部","value":"集团总部"},{"label":"成渝区域","value":"成渝区域"},{"label":"两湖区域","value":"两湖区域"},{"label":"川北区域","value":"川北区域"},{"label":"川南区域","value":"川南区域"},{"label":"中原区域","value":"中原区域"},{"label":"攀西区域","value":"攀西区域"},{"label":"新疆区域","value":"新疆区域"},{"label":"大湾区域","value":"大湾区域"},{"label":"北京区域","value":"北京区域"},{"label":"园林公司","value":"园林公司"}]},{"label":"金融板块","value":"金融板块"},{"label":"物业板块","value":"物业板块"},{"label":"医疗健康板块","value":"医疗健康板块"},{"label":"商业板块","value":"商业板块"},{"label":"合作方财务公司","value":"合作方财务公司"}]`),
      },
      id:'',
      element: {
          create_by:'admin',
          create_time: dayjs().format('YYYY-MM-DD'),
          groupname:'',
          userlist:'',
          userlist_reception:'',
          userlist_reception_name:'',
          enuserlist:'',
          userlist_execute:'',
          zonename: ['地产板块','集团总部'], //所属区域
          teamname:'',
          company:'',
          address:'',
          platename:'地产板块',
          status:'valid',
          access:[],
          remark: '暂无备注', //备注信息
      },
      data: [],
      userData:[],
      userDataSource:[],
      companyDataSource:[],
      readonly: false,
      userList:[],
      firmlist:[],
      firmNamelist:[],
      release_userlist:[],
      approve_userlist:[],
      approve_executelist:[],
      role:'',
      file:'',
      selectedSheet: null,
      sheetName: null,
      collection: [{ }],
      userinfo: '',
      usertitle:'',
      columns: workconfig.columns.reward.items,
      wfcolumns: workconfig.columns.reward.wfcolumns,
      message: workconfig.compValidation.legalapply.message,
      valid: workconfig.compValidation.legalapply.valid,
      goodsborrowtype: workconfig.goodsborrowtype,
      diplomaType: workconfig.compcolumns.diplomaTypeColumns,
      acceptType: workconfig.compcolumns.acceptType,
      commonTypeColumns: workconfig.compcolumns.commonTypeColumns,
      sealTypeColumns: workconfig.compcolumns.sealTypeColumns,
      statusList:['存续','注销','经营异常'],
      natureList:['关联公司','非关联公司'],
      roleList:[{name:'股权管理员',value:'STOCK_OPERATE_ADMIN'},{name:'股权查询员',value:'STOCK_VIEW_ADMIN'},{name:'系统管理员',value:'SYSTEM_ADMIN'},{name:'资质管理员',value:'LICENSE_ADMIN'},{name:'产权管理员',value:'PROPERTY_ADMIN'},{name:'印章保管员',value:'SEAL_ADMIN'},{name:'案件管理员',value:'LEGAL_OPERATE_ADMIN'},{name:'法务管理员',value:'LEGAL_ADMIN'},{name:'物品管理员',value:'COMMON_RECEIVE_BORROW'},{name:'来访管理员',value:'COMMON_VISIT_AUTH'}],
      roleAccessList:{'STOCK_OPERATE_ADMIN':'myreward-access,mydone-access,mytodo-access,myapply-access,companyapply-access,pledgeapply-access,qualificationapply-access,annalsapply-access,companylist-access,subsidyapply-access,alterationapply-access,punishmentapply-access,accountapply-access,licenseapply-access,prolicenseapply-access,otherlicenseapply-access,trademarkapply-access,softwareapply-access,worksapply-access,recordapply-access','STOCK_VIEW_ADMIN':'myreward-access,mydone-access,mytodo-access,myapply-access,companylist-access','SYSTEM_ADMIN':'myreward-access,mydone-access,mytodo-access,myapply-access,accessapply-access','LICENSE_ADMIN':'myreward-access,mytodo-access,mydone-access,myapply-access,licenseapply-access,prolicenseapply-access,otherlicenseapply-access','PROPERTY_ADMIN':'myreward-access,mytodo-access,mydone-access,myapply-access,trademarkapply-access,softwareapply-access,worksapply-access,recordapply-access','SEAL_ADMIN':'myreward-access,mytodo-access,mydone-access,myapply-access','LEGAL_OPERATE_ADMIN':'myreward-access,mytodo-access,mydone-access,myapply-access','LEGAL_ADMIN':'myreward-access,mytodo-access,mydone-access,myapply-access','COMMON_RECEIVE_BORROW':'myreward-access,mytodo-access,mydone-access,myapply-access','COMMON_VISIT_AUTH':'myreward-access,mytodo-access,mydone-access,myapply-access'},
      accessList:[{name:'我的知会',value:'myreward-access'},{name:'我的待办',value:'mytodo-access'},{name:'我的已办',value:'mydone-access'},{name:'我的申请',value:'myapply-access'},{name:'设立公司申请',value:'companyapply-access'},{name:'录入质押申请',value:'pledgeapply-access'},{name:'录入资质申请',value:'qualificationapply-access'},{name:'录入年报申请',value:'annalsapply-access'},{name:'公司工商查询',value:'companylist-access'},{name:'录入补贴记录',value:'subsidyapply-access'},{name:'录入变更记录',value:'alterationapply-access'},{name:'录入处罚记录',value:'punishmentapply-access'},{name:'录入账号记录',value:'accountapply-access'},{name:'录入营业执照',value:'licenseapply-access'},{name:'录入项目证照',value:'prolicenseapply-access'},{name:'录入其他证照',value:'otherlicenseapply-access'},{name:'录入商标信息申请',value:'trademarkapply-access'},{name:'录软件著作权申请',value:'softwareapply-access'},{name:'录作品著作权申请',value:'worksapply-access'},{name:'录入网站备案申请',value:'recordapply-access'},{name:'系统权限申请',value:'accessapply-access'}],
      industryList:[ '地产板块', '金融板块', '物业板块', '医疗健康板块', '商业板块','合作方财务公司'],
      breadcrumb:[{icon:'home',text:'首页',path:'/stock/workspace'},{icon:'user',text:'系统管理',path:'/stock/workspace'},{icon:'form',text:'系统权限申请',path:''}],
      statusType:{'valid':'有效','invalid':'删除'},
      zoneType:{'领地集团总部':'领地集团总部','成渝区域':'成渝区域','两湖区域':'两湖区域','川北区域':'川北区域','川南区域':'川南区域','中原区域':'中原区域','攀西区域':'攀西区域','新疆区域':'新疆区域','大湾区域':'大湾区域','北京区域':'北京区域'},
    };
  },
  activated() {
    this.queryInfo();
  },
  mounted() {
    this.queryInfo();
  },
  methods: {
      moment,
      isNull:Betools.tools.isNull,
      deNull:Betools.tools.deNull,

      // 名称过滤
      filterOption(input, option) {
        return (
          option.componentOptions.children[0].text.toUpperCase().indexOf(input.toUpperCase()) >= 0
        );
      },

      // 企业微信登录处理函数
      async  weworkLogin  (codeType = 'search', systemType = 'search', version = 'v4')  {
          /**
           URL直连模式登陆：http://stock.yunwisdom.club:30080/#/?mode=session&mobile=19999763013&account=bWVuZ3Fm
            1. mobile请替换为登录人的mobile。
            2. account请替换为登录人的account，注意account需要使用window.btoa('args')函数处理一下。
           */
          return await Betools.query.weworkLogin(codeType, systemType, version);
      },
      
      // 执行页面跳转
      async redirectView(path) {
          Betools.tools.isNull(path) ? null: this.$router.push(path);
      },
     
      // 获取基础信息
      async queryInfo() {

        try {

          try {
            this.iswechat = Betools.tools.isWechat(); //查询当前是否微信端
            this.iswework = Betools.tools.isWework(); //查询是否为企业微信
          } catch (error) {
            console.error(error);
          }

          try {
            const weworkinfo = await this.weworkLogin('search','search','v4'); //查询当前登录用户
            this.userinfo = weworkinfo.userinfo;
            this.usertitle = weworkinfo.usertitle;
            this.back = Betools.tools.getUrlParam('back') || '/stock/workspace'; //查询上一页
          } catch (error) {
            console.error(error);
          }
          
          const userinfo = await Betools.storage.getStore('system_userinfo');  //获取用户基础信息
          const id = this.id = Betools.tools.getUrlParam('id');
          
          if(!Betools.tools.isNull(id)){
            this.element = await this.handleList(this.tablename , id);
          }
          
          try {
            this.element.create_by = (userinfo ? userinfo.realname || userinfo.name || userinfo.lastname : '');
          } catch (error) {
            console.error(error);
          } 
        } catch (error) {
          console.log(error);
        }
      },

      // 查询不同状态的律所数据
      async handleList(tableName , id){
        let element = await Betools.query.queryTableData(tableName , id);
        try {
          element.zonename = element.zonename.includes(',') ? element.zonename.split(',') : element.zonename;
          element.access = element.access.includes(',') ? element.access.split(',') : element.access;
        } catch (error) {
          console.error(error);
        }
        return !Betools.tools.isNull(element) ? element : {};
      },

      // 验证字段
      validField(fieldName){
        return Betools.tools.isNull(this.element[fieldName]);
      },

      // 验证字段信息
      validFieldToast(fieldName){
        const tipsession = { zonename:'请选择所属区域！', platename:'请输入所属板块！', company:'请输入所属项目公司/名称！', groupname:'请输入岗位/角色！', userlist:'请输入OA账户！', userlist_reception_name:'请输入账户名称！', access:'请选择该用户所拥有的权限！',};
        const flag = this.validField(fieldName);
        if(flag){
          Betools.tools.isNull(tipsession[fieldName]) ? null : this.$toast.fail(`${tipsession[fieldName]}！` );
          return false;
        }
      },

      // 查询输入内容对应的账户
      async handleSearch(searchText) {
        if(!Betools.tools.isNull(searchText)){
          const userData = await Betools.query.querySystemAccountList('v_hrmresource', searchText, 0 , 20);
          if(userData && userData.length > 0){
            this.userData = userData;
            this.userDataSource = userData.map(e=>e.name);
          }
        } else {
          this.userDataSource = [];
        }
      },

      // 获取选中数据
      async handleSelect(value) {
        const data = this.userData.find(e=>e.name == value);
        this.element.userlist = this.element.userlist_reception = data.loginid;
      },

      // 获取选中岗位/角色
      async handleChange(value){
        const access = this.roleAccessList[value];
        this.element.access = access.split(',');
      },
        
      // 用户提交入职登记表函数
      async handleApply() {
        await this.handleSave(); //先执行保存操作，保存完毕后执行流程跳转功能
      },

      // 保存用户数据但是不提交
      async handleSave(){
        
        this.loading = true; // 显示加载状态
        const userinfo = await Betools.storage.getStore('system_userinfo'); // 获取用户基础信息
        const id = Betools.tools.queryUniqueID(); // 表单ID

        try {
          this.element.id = id;
          this.element.create_time = dayjs().format('YYYY-MM-DD');
          this.element.create_by = (userinfo ? userinfo.realname || userinfo.name || userinfo.lastname : '');
          this.element.zonename = this.element.zonename.toString();
          this.element.access = this.element.access.toString();
        } catch (error) {
          console.error(error);
        }

        const tipsession = { zonename:'请选择所属区域！', platename:'请输入所属板块！', company:'请输入所属项目公司/名称！', groupname:'请输入岗位/角色！', userlist:'请输入OA账户！', userlist_reception_name:'请输入账户名称！', access:'请选择该用户所拥有的权限！',};
        const keys = Object.keys(tipsession); // 验证数据是否已经填写

        const invalidKey =  keys.find(key => {
          const flag = this.validField(key); // const returnValue = flag ? key : '';
          return flag;
        });

        if(!Betools.tools.isNull(invalidKey)){
            return await vant.Dialog.alert({  title: '温馨提示',  message: `您好，${tipsession[invalidKey]}`, });
        }

        // 是否确认提交此自由流程?
        this.$confirm({
            title: "确认操作",
            content: "是否确认提交此系统权限申请单?",
            onOk: async() => {
                  const element  = JSON.parse(JSON.stringify(this.element));
                  const result = await Betools.manage.postTableData(this.tablename , element); // 向表单提交form对象数据
                  if(result && result.error && result.error.errno){ //提交数据如果出现错误，请提示错误信息
                      return await vant.Dialog.alert({  title: '温馨提示',  message: `系统错误，请联系管理人员，错误编码：[${result.error.code}]. `, });
                  }
                  this.loading = false; //设置状态
                  this.readonly = true;
                  this.role = 'view';
                  this.handleList(this.tablename , id);
                  return vant.Dialog.alert({  title: '温馨提示',  message: `系统权限申请提交成功！`, }); //this.$toast.success('律师录入申请成功！');
               }
          });
      },

      // 修改用户数据但是不提交
      async handlePatch(){
        
        this.loading = true; // 显示加载状态
        const userinfo = await Betools.storage.getStore('system_userinfo'); // 获取用户基础信息
        const id = Betools.tools.getUrlParam('id'); // 表单ID

        try {
          this.element.create_time = dayjs().format('YYYY-MM-DD');
          this.element.create_by = (userinfo ? userinfo.realname || userinfo.name || userinfo.lastname : '');
          this.element.zonename = this.element.zonename.toString();
          this.element.access = this.element.access.toString();
        } catch (error) {
          console.error(error);
        }

        const tipsession = { zonename:'请选择所属区域！', platename:'请输入所属板块！', company:'请输入所属项目公司/名称！', groupname:'请输入岗位/角色！', userlist:'请输入OA账户！', userlist_reception_name:'请输入账户名称！', access:'请选择该用户所拥有的权限！',};
        const keys = Object.keys(tipsession); // 验证数据是否已经填写

        const invalidKey =  keys.find(key => {
          const flag = this.validField(key); // const returnValue = flag ? key : '';
          return flag;
        });

        if(!Betools.tools.isNull(invalidKey)){
            return await vant.Dialog.alert({  title: '温馨提示',  message: `您好，${tipsession[invalidKey]}`, });
        }

        //是否确认提交此自由流程?
        this.$confirm({
            title: "确认操作",
            content: "是否确认修改此设立公司申请单?",
            onOk: async() => {
                  const element  = JSON.parse(JSON.stringify(this.element));
                  const result = await Betools.manage.patchTableData(this.tablename, id, element); // 向表单提交form对象数据
                  if(result && result.error && result.error.errno){ //提交数据如果出现错误，请提示错误信息
                      return await vant.Dialog.alert({  title: '温馨提示',  message: `系统错误，请联系管理人员，错误编码：[${result.error.code}]. `, });
                  }
                  this.loading = false;
                  this.readonly = true;
                  this.role = 'view';
                  this.handleList(this.tablename , id);
                  return vant.Dialog.alert({  title: '温馨提示',  message: `修改操作成功！`, }); //this.$toast.success('律师修改操作成功！');
               }
          });
      },

  },
};
</script>
<style scoped >
    @import "../../../assets/css/reward.home.css";
    @import "../../../assets/css/reward.apply.css";
</style>
